import java.util.Random;

public class hw0815 {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// trimString("a jh g");
		// System.out.print(indexInString("gdjfgsdhjfghs", "jf"));
		unionArr(new int[]{1, 2, 3, 3, 4}, new int[]{3, 4, 4, 5});
	}

	/**
	 * 23
	 * 
	 * @param chineseNumberString
	 *            中文大写数字字符串
	 * @return 装换后的int类型阿拉伯数字
	 */
	public static int chineseNumberToInt(String chineseNumberString) {
		char ch;
		String temp = "";
		int sum = 0;
		for (int i = 0; i < chineseNumberString.length(); i++) {
			ch = chineseNumberCharToIntChar(chineseNumberString.charAt(i));
			if (ch != '-') {
				temp += ch;
			}
		}
		int len = temp.length();
		for (int i = 0; i < len; i++) {
			sum += Math.pow(10, len - 1 - i) * (temp.charAt(i) - '0');
		}
		return sum;
	}

	/**
	 * @param chineseNumberChar
	 *            中文大写数字字符，如“壹”，“贰”，“叁”。。。
	 * @return 转换成的阿拉伯数字，类型char,‘-’代表传入的非中文大写数字
	 */
	private static char chineseNumberCharToIntChar(char chineseNumberChar) {
		char[] chars = new char[]{'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌',
				'玖'};
		char ch = '-';
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] == chineseNumberChar) {
				ch = (char) (i + '0');
			}
		}
		return ch;
	}
	/**
	 * 22
	 * 
	 * @param number
	 *            int类型非负整数
	 * @return 装换后的中文大写数字字符串,负数返回null
	 */
	public static String decimalNumTocChineseNumber(int number) {
		int temp = number;
		String newString = "", tempString = "";
		if (temp >= 0) {
			while (temp > 9) {
				tempString += arabicTochineseNumberChar(temp % 10);
				temp = temp / 10;
			}
			tempString += arabicTochineseNumberChar(temp);
			for (int i = tempString.length() - 1; i >= 0; i--) {
				newString += tempString.charAt(i);
			}
			return newString;
		} else {
			return null;
		}
	}

	/**
	 * @param arabicNumerals
	 *            阿拉伯数字,1,2,3,4...
	 * @return 转换成的中文大写数字，类型char,如“壹”，“贰”，“叁”...;‘-’代表传入的非阿拉伯数字
	 */
	private static char arabicTochineseNumberChar(int arabicNumerals) {
		char[] chars = new char[]{'零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌',
				'玖'};
		if (arabicNumerals > 9 || arabicNumerals < 0) {
			return '-';
		} else {
			return chars[arabicNumerals];
		}
	}

	/**
	 * 21
	 * 
	 * @param hexadecimalString
	 *            十六进制数字，String
	 * @return 十进制数字,int
	 */
	public static int hexToDecimalism(String hexadecimalString) {
		String tempString = lowercaseToUpperCase(hexadecimalString);
		char ch;
		boolean flag = true;
		int sum = 0;
		for (int i = 0; i < tempString.length(); i++) {
			ch = tempString.charAt(i);
			if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) {
				flag = true;
			} else {
				flag = false;
				break;
			}
		}
		if (flag) {
			for (int i = 0; i < tempString.length(); i++) {
				sum += Math.pow(16, tempString.length() - 1 - i)
						* hexadecimalCharToInt(tempString.charAt(i));
			}
		}
		return sum;
	}

	/**
	 * @param hexadecimalChar
	 *            十六进制字符，如'1','2','4',...,'9','A',..,'F'
	 * @return 转换成的阿拉伯数字，类型int,16代表传入字符非法
	 */
	private static int hexadecimalCharToInt(char hexadecimalChar) {
		char[] chars = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8',
				'9', 'A', 'B', 'C', 'D', 'E', 'F'};
		int index = 16;
		for (int i = 0; i < chars.length; i++) {
			if (chars[i] == hexadecimalChar) {
				index = i;
			}
		}
		return index;
	}

	/**
	 * @param inputString
	 *            待转换字符串
	 * @return 小写英文字母转换为大写英文字母后的字符串
	 */
	private static String lowercaseToUpperCase(String inputString) {
		String newString = "";
		char ch;
		for (int i = 0; i < inputString.length(); i++) {
			ch = inputString.charAt(i);
			if (ch >= 'a' && ch <= 'z') {
				newString += (char) (ch - 32);
			} else {
				newString += ch;
			}
		}
		return newString;
	}

	/**
	 * 20
	 * 
	 * @param decimalVal
	 *            十进制数字,int
	 * @return 十六进制字符串,String,负值返回null
	 */
	public static String decimalValTohex(int decimalVal) {
		int temp = decimalVal;
		String newString = "", resultString = "";
		if (temp >= 0) {
			while (temp > 15) {
				newString += decimalTohexChar(temp % 16);
				temp = temp / 16;
			}
			newString += decimalTohexChar(temp);
			for (int i = newString.length() - 1; i >= 0; i--) {
				resultString += newString.charAt(i);
			}
			return resultString;
		} else {
			return null;
		}
	}

	/**
	 * 
	 * @param intVal
	 *            十进制数字,int，0,1,...,15
	 * @return 十六进制字符，如'1','2','4',...,'9','A',..,'F','-'表示输入有误
	 */
	private static char decimalTohexChar(int intVal) {
		char[] chars = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8',
				'9', 'A', 'B', 'C', 'D', 'E', 'F'};
		char ch = '-';
		if (intVal >= 0 && intVal < 16) {
			ch = chars[intVal];
		}
		return ch;
	}

	/**
	 * 19
	 * 
	 * @param binaryString
	 *            二进制字符串
	 * @return 十进制int类型数字，-1，代表输入的二进制字串格式错误
	 */
	public static int binaryStringTodecimalVal(String binaryString) {
		boolean flag = true;
		char ch;
		int sum = 0;
		for (int i = 0; i < binaryString.length(); i++) {
			ch = binaryString.charAt(i);
			if (ch == '0' || ch == '1') {
				continue;
			} else {
				flag = false;
				break;
			}
		}
		if (flag) {
			for (int i = 0; i < binaryString.length(); i++) {
				sum += Math.pow(2, binaryString.length() - 1 - i)
						* (binaryString.charAt(i) - '0');
			}
			return sum;
		} else {
			return -1;
		}
	}

	/**
	 * 18
	 * 
	 * @param decimalVal
	 *            十进制数字,int
	 * @return 二进制字符串,String,负值返回null
	 */
	public static String decimalValToBinaryString(int decimalVal) {
		int temp = decimalVal;
		String newString = "", resultString = "";
		if (temp >= 0) {
			while (temp > 0) {
				newString += temp % 2 - '0';
				temp = temp / 2;
			}
			for (int i = newString.length() - 1; i >= 0; i--) {
				resultString += newString.charAt(i);
			}
			return resultString;
		} else {
			return null;
		}
	}

	/**
	 * 16
	 * 
	 * @param size
	 *            要生成的苏尔特数组的尺度，即行数或列数
	 * @return 生成的苏尔特数组
	 */
	public static int[][] generateSoultArray(int size) {
		Random random = new Random();
		int top = size * size, temp;
		int[][] outArr = new int[size][size];
		int[] tempArr = new int[top];
		for (int i = 0; i < tempArr.length; i++) {
			tempArr[i] = i + 1;
		}
		for (int i = 0; i < outArr.length; i++) {
			for (int j = 0; j < outArr[0].length; j++) {
				temp = random.nextInt(top);
				outArr[i][j] = tempArr[temp];
				top--;
				tempArr[temp] = tempArr[top];
				// tempArr[top] = 0;
				System.out.print(outArr[i][j] + "\t");
			}
			System.out.println();
		}
		return outArr;
	}

	/**
	 * 16
	 * 
	 * @param size
	 *            要生成的苏尔特数组的尺度，即行数或列数
	 * @return 生成的苏尔特数组
	 */
	public static int[][] generateSoultArray2(int size) {
		int index = 0;
		int[][] outArr = new int[size][size];
		int[] tempArr = seedArray(size * size);
		for (int i = 0; i < outArr.length; i++) {
			for (int j = 0; j < outArr[0].length; j++) {
				outArr[i][j] = tempArr[index];
				index++;
				System.out.print(outArr[i][j] + "\t");
			}
			System.out.println();
		}
		return outArr;
	}

	/**
	 * 
	 * @param size
	 *            乱序的一位数组的长度
	 * @return 生成的乱序1~size数组
	 */
	public static int[] seedArray(int size) {
		Random random = new Random();
		int index, temp;
		int[] tempArr = new int[size];
		for (int i = 0; i < tempArr.length; i++) {
			tempArr[i] = i + 1;
		}
		for (int i = size - 1; i > 1; i--) {
			index = random.nextInt(i);
			temp = tempArr[index];
			tempArr[index] = tempArr[i];
			tempArr[i] = temp;
		}
		// for (int i = 0; i < tempArr.length; i++) {
		// System.out.print(tempArr[i] + "\t");
		// }
		return tempArr;
	}

	/**
	 * 1
	 * 
	 * @param year
	 *            年份，一般应该是4位数
	 * @return true 是闰年， false 不是闰年
	 */
	public static boolean isLeapYear(int year) {
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 2
	 * 
	 * @param val
	 *            三位整数
	 * @return true 是水仙花数 false 不是水仙花数
	 */
	public static boolean isNarcissisticNumber(int val) {
		if (val >= 100 && val < 1000) {
			int a = val / 100;
			int b = val / 10 % 10;
			int c = val % 10;
			if (val == a * a * a + b * b * b + c * c * c) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	/**
	 * 3
	 * 
	 * @param radius
	 *            圆的半径，应大于0
	 * @return 圆的面积，-1表明输入半径非合理值
	 */
	public static double getCircleAreaByRadius(Double radius) {
		if (radius > 0) {
			return Math.PI * radius * radius;
		} else {
			return -1;
		}
	}

	/**
	 * 4
	 * 
	 * @param a
	 *            一元二次方程系数a
	 * @param b
	 *            一元二次方程系数b
	 * @param c
	 *            一元二次方程系数c
	 * @return true：方程实数范围内有解， false：方程实数范围内无解
	 */
	public static boolean hasSolution(Double a, Double b, Double c) {
		if (a == 0) {
			return false;
		} else {
			double delta = b * b - 4 * a * c;
			if (delta >= 0) {
				return true;
			} else {
				return false;
			}
		}
	}

	/**
	 * 5
	 * 
	 * @param a
	 *            整数1，应大约0
	 * @param b
	 *            整数2，应大约0
	 * @return 整数1，整数2的最大公约数
	 */
	public static int getMaxCommonDivision(int a, int b) {
		int temp;
		if (a <= 0 || b <= 0) {
			return 0;
		}
		if (a < b) {
			temp = a;
			a = b;
			b = temp;
		}
		if (a % b == 0) {
			return b;
		}
		for (int i = b / 2; i > 1; i--) {
			if (a % i == 0 && b % i == 0) {
				return i;
			}
		}
		return 1;
	}

	/**
	 * 6
	 * 
	 * @param fileName
	 *            文件名
	 * @return 文件的扩展名，返回null表明输入文件名不完整
	 */
	public static String getExtensionName(String fileName) {
		int index = -1;
		String temp = "";
		for (int i = fileName.length() - 2; i >= 0; i--) {
			if (fileName.charAt(i) == '.') {
				index = i;
				break;
			}
		}
		if (index == -1) {
			return null;
		} else {
			for (int i = index + 1; i < fileName.length(); i++) {
				temp += fileName.charAt(i);
			}
		}
		return temp;
	}
	/**
	 * 7
	 * 
	 * @param email
	 *            邮件地址
	 * @return true：邮件地址符合标准格式， false：邮件地址不符合标准格式
	 */
	public static boolean doesMeetEmailFormat(String email) {
		int len = email.length();
		int indexAt = 0, countAt = 0;
		int indexDot = 0, countDot = 0;
		if (len < 5) {
			return false;
		}
		if (email.charAt(0) == '@' || email.charAt(0) == '.'
				|| email.charAt(len - 1) == '@' || email.charAt(len - 1) == '.') {
			return false;
		}
		for (int i = len - 2; i > 0; i--) {
			if (email.charAt(i) == '@') {
				indexAt = i;
				countAt++;
			}
			if (email.charAt(i) == '.') {
				indexDot = i;
				countDot++;
			}
		}
		if (countAt == 1 && countDot > 0 && countDot < 3
				&& indexAt + 1 < indexDot) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 8
	 * 
	 * @param inpuString
	 *            目标字符串
	 * @param searchChar
	 *            要查询的字符
	 * @return 指定字符在目标字符串中出现的次数，0表明未出现
	 */
	public static int getCharCountInString(String inpuString, char searchChar) {
		int count = 0;
		for (int i = 0; i < inpuString.length(); i++) {
			if (inpuString.charAt(i) == searchChar) {
				count++;
			}
		}
		return count;
	}

	/**
	 * 9
	 * 
	 * @param inpuString
	 *            待转换的字符串
	 * @return 字符串中大写字母转换成小写字母的结果
	 */
	public static String toLowercase(String inpuString) {
		String newString = "";
		char ch;
		for (int i = 0; i < inpuString.length(); i++) {
			ch = inpuString.charAt(i);
			if (ch >= 'a' && ch <= 'z') {
				newString += (char) (ch + ('A' - 'a'));
			} else {
				newString += ch;
			}
		}
		return newString;
	}

	/**
	 * 10
	 * 
	 * @param inpuString
	 *            待截取的字符串
	 * @param startIndex
	 *            截取的起始索引（index）位置，应小于字符串最大索引
	 * @param cutoutLength
	 *            截取的长度，应大于0
	 * @return 截取后的字符串，null代表起始索引越界等错误
	 */
	public static String cutoutString(String inpuString, int startIndex,
			int cutoutLength) {
		String newString = "";
		int len = inpuString.length();
		if (cutoutLength < 1 || startIndex > len - 1
				|| startIndex + cutoutLength > len) {
			return null;
		} else {
			for (int i = startIndex; i < startIndex + cutoutLength; i++) {
				newString += inpuString.charAt(i);
			}
			return newString;
		}
	}
	/**
	 * 11
	 * 
	 * @param inpuString
	 *            待分割的字符串
	 * @param splitChar
	 *            分割字符
	 * @return 分割后的字符串组,null表示输入参数有误
	 */
	public static String[] splitString(String inpuString, char splitChar) {
		if (inpuString == "" || inpuString == null
				|| inpuString == splitChar + "") {
			return null;
		}
		int len = inpuString.length(), top = 0;
		for (int i = 0; i < len; i++) {
			if (inpuString.charAt(i) == splitChar) {
				top++;
			}
		}
		if (top == 0 || top == len) {
			return null;
		}
		int[] indexs = new int[len];
		top = 0;
		if (inpuString.charAt(0) == splitChar) {
			indexs[top] = 0;
		} else {
			indexs[top] = -1;
		}
		top++;
		for (int i = 1; i < len - 1; i++) {
			if (inpuString.charAt(i) == splitChar) {
				indexs[top] = i;
				top++;
			}
		}
		if (inpuString.charAt(len - 1) == splitChar) {
			indexs[top] = len - 1;
		} else {
			indexs[top] = len;
		}
		String[] strings = new String[top];
		for (int i = 0; i < top; i++) {
			strings[i] = "";
			for (int j = indexs[i] + 1; j < indexs[i + 1]; j++) {
				strings[i] += inpuString.charAt(j);
			}
		}
		for (int i = 0; i < strings.length; i++) {
			System.out.print(strings[i] + "\t");
		}
		return strings;
	}

	/**
	 * 12
	 * 
	 * @param inpuString
	 *            待处理的字符串
	 * @return 去除左右空格的字符串
	 */
	public static String trimString(String inpuString) {
		if (inpuString == "" || inpuString == null) {
			return null;
		}
		int len = inpuString.length(), count = 0;
		for (int i = 0; i < len; i++) {
			if (inpuString.charAt(i) == ' ') {
				count++;
			}
		}
		if (count == len) {
			return null;
		}
		if (count == 0) {
			System.out.println(inpuString);
			return inpuString;
		}
		int indexS = -1, indexE = len;
		String newString = "";
		if (inpuString.charAt(0) == ' ') {
			indexS = 0;
			for (int i = 0; i < len - 1; i++) {
				if (inpuString.charAt(i) == ' '
						&& inpuString.charAt(i + 1) != ' ') {
					indexS = i;
					break;
				}
			}
		}
		if (inpuString.charAt(len - 1) == ' ') {
			for (int i = len - 1; i > 0; i--) {
				if (inpuString.charAt(i) == ' '
						&& inpuString.charAt(i - 1) != ' ') {
					indexE = i;
					break;
				}
			}
		}
		for (int i = indexS + 1; i < indexE; i++) {
			newString += inpuString.charAt(i);
		}
		System.out.println("=" + newString + "=");
		return newString;
	}

	/**
	 * 13
	 * 
	 * @param inputString
	 *            目标字符串
	 * @param searchString
	 *            待查找的字符串
	 * @return 索引值
	 */
	public static int indexInString(String inputString, String searchString) {
		int index = -1, count = 1;
		int lenI = inputString.length();
		int lenS = searchString.length();
		if (lenS <= lenI) {
			for (int i = 0; i <= lenI - lenS; i++) {
				if (searchString.charAt(0) == inputString.charAt(i)) {
					for (int j = 1; j < lenS; j++) {
						if (searchString.charAt(j) == inputString.charAt(i + j)) {
							count++;
						}
					}
				}
				if (count == lenS) {
					index = i;
					break;
				}
			}
		}
		return index;
	}

	/**
	 * 
	 * @param arrA int数组集合1
	 * @param arrB int数组集合2
	 * @return 两个集合的并集
	 */
	
	public static int[] unionArr(int[] arrA, int[] arrB) {
		int[] newArr = new int[arrA.length + arrB.length];
		int top = arrA.length, temp;
		for (int i = 0; i < arrA.length; i++) {
			newArr[i] = arrA[i];
		}
		for (int i = 0; i < arrB.length; i++) {
			newArr[top] = arrB[i];
			top++;
		}
		for (int i = 0; i < arrA.length; i++) {
			for (int j = arrA.length; j < top; j++) {
				if (arrA[i] == newArr[j]) {
					temp = newArr[top - 1];
					newArr[top - 1] = newArr[j];
					newArr[j] = temp;
					top--;
					break;
				}
			}
		}
		int[] arr = new int[top];
		for (int i = 0; i < arr.length; i++) {
			arr[i] = newArr[i];
		}
		for (int item : arr) {
			System.out.print(item + "\t");
		}
		return arr;
	}
}
